#include "HardwareProfile.h"
unsigned char Uint0;
const unsigned char Num4[10][2]=
{
	0b00001101,0b00001111,
	0b00001000,0b00000110,
	0b00001110,0b00001011,
	0b00001010,0b00001111,
	0b00001011,0b00000110,
	0b00001011,0b00001101,
	0b00001111,0b00001101,
	0b00001000,0b00000111,
	0b00001111,0b00001111,
	0b00001011,0b00001111,
};
const unsigned char Num[10][2]=
{
	0b00001111,0b00001101,
	0b00000110,0b00001000,
	0b00001011,0b00001110,
	0b00001111,0b00001010,
	0b00000110,0b00001011,
	0b00001101,0b00001011,
	0b00001101,0b00001111,
	0b00000111,0b00001000,
	0b00001111,0b00001111,
	0b00001111,0b00001011,
};
void Display_Clear(void)
{
	unsigned char i;
	for(i=0;i<16;i++)
		HT162X_WriteData(i,0);
}
void Display_Init(void)
{
	Display_WorkTime();
	Display_WorkCycle();
	HT162X_WriteData(9,0x0f);
	HT162X_WriteData(2,0x07);
	HT162X_WriteData(3,0x0f);
	HT162X_WriteData(4,0x0f);
	HT162X_WriteData(5,0x0f);
	HT162X_WriteData(6,0x0f);
	HT162X_WriteData(7,0x0f);
	HT162X_WriteData(8,0x0e);
	Display_Flash();
}
void Display_ID(void)
{
	unsigned char x,y,ID1,ID2;
	ID1=eeprom_read(250);
	ID2=eeprom_read(251);
	x=ID1%10;
	y=ID1/10;
	HT162X_WriteData(14,Num[y][0]);
	HT162X_WriteData(15,Num[y][1]&0xf7);
	HT162X_WriteDatas(12,Num[x],2);
	x=ID2%10;
	y=ID2/10;
	HT162X_WriteData(10,Num[y][0]);
	HT162X_WriteData(11,Num[y][1]&0xf7);
	HT162X_WriteData(0,Num4[x][0]&0xf7);
	HT162X_WriteData(1,Num4[x][1]);
	HT162X_WriteData(2,0x02);
}
void Display_WorkTime(void)
{
	unsigned char x,y;
	x=WorkTime%10;
	y=WorkTime/10;
	HT162X_WriteDatas(14,Num[y],2);
	HT162X_WriteDatas(12,Num[x],2);
}
void Display_WorkCycle(void)
{
	unsigned char x,y;
	x=WorkCycle%10;
	y=WorkCycle/10;
	HT162X_WriteDatas(10,Num[y],2);
	Uint0=Num4[x][0];
	if(gFlags.Bits.bSet)
	{
		if(gFlags.Bits.bShow)
		{
			HT162X_WriteDatas(0,Num4[x],2);	
		}
		else
		{			
			HT162X_WriteData(0,Num4[x][0]&0xf7);
			HT162X_WriteData(1,Num4[x][1]);
		}
	}	
	else
		HT162X_WriteDatas(0,Num4[x],2);	
}
void Display_Flash(void)
{
	unsigned char x;
	x=0x07;
	if(gFlags.Bits.bID)
		return;
	if(gFlags.Bits.bShow)
	{
		if(gFlags.Bits.bSet)
		{			
			HT162X_WriteData(0,Uint0&0xf7);
		}
		if(gFlags.Bits.bWork)
			x=x|0x08;
		else
		{
			HT162X_WriteData(8,0x0f);
			HT162X_WriteData(7,0x0f);
		}
		HT162X_WriteData(2,x);		
	}
	else
	{
		if(gFlags.Bits.bSet)
		{
			x=x&0xfe;
			HT162X_WriteData(0,Uint0|0x08);
		}
		if(gFlags.Bits.bWork)
			x=x&0xf7;
		else
		{
			HT162X_WriteData(8,0x0e);
			HT162X_WriteData(7,0x0e);
		}
		HT162X_WriteData(2,x);		
	}	
}